home *** CD-ROM | disk | FTP | other *** search
/ fxPAINT 1.0 / fxPAINT 1.0.iso / developers / plugins / exampleplugin / lib_source / libinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-05  |  4.8 KB  |  162 lines

  1. /*
  2. **      $VER: LibInit.c 1.00 (9.8.1999)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1999 Felix Schwarz
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/libraries.h>
  15. #include <exec/execbase.h>
  16. #include <exec/resident.h>
  17. #include <exec/initializers.h>
  18.  
  19. #include <proto/exec.h>
  20.  
  21. #include "compiler.h"
  22. #include "base.h"
  23.  
  24. ULONG __saveds __stdargs L_OpenLibs(void);
  25. void  __saveds __stdargs L_CloseLibs(void);
  26.  
  27. extern struct ExampleBase *ExampleBase;
  28.  
  29. struct ExecBase      *SysBase       = NULL;
  30. struct IntuitionBase *IntuitionBase = NULL;
  31. struct GfxBase       *GfxBase       = NULL;
  32. struct GadToolsBase  *GadToolsBase  = NULL;
  33. struct DOSLibrary    *DOSBase       = NULL;
  34.  
  35. #define VERSION  1
  36. #define REVISION 00
  37.  
  38. char __aligned ExLibName [] = "example.plugin";
  39. char __aligned ExLibID   [] = "example 1.00 "__AMIGADATE__"";
  40. char __aligned Copyright [] = "(C)opyright 1999 by Felix Schwarz. All rights reserved.";
  41.  
  42. extern ULONG InitTab[];
  43. extern APTR EndResident;
  44.  
  45. struct Resident __aligned ROMTag =
  46. {
  47.  RTC_MATCHWORD,
  48.  &ROMTag,
  49.  &EndResident,
  50.  RTF_AUTOINIT,
  51.  VERSION,
  52.  NT_LIBRARY,
  53.  0,
  54.  &ExLibName[0],
  55.  &ExLibID[0],
  56.  &InitTab[0]
  57. };
  58.  
  59. APTR EndResident;
  60.  
  61. struct MyDataInit
  62. {
  63.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  64.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  65.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  66.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  67.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  68.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  69.  ULONG ENDMARK;
  70. } DataTab =
  71. #ifdef VBCC
  72. {
  73.         0xe000,8,NT_LIBRARY,
  74.         0x0080,10,(ULONG) &ExLibName[0],
  75.         0xe000,LIBF_SUMUSED|LIBF_CHANGED,
  76.         0xd000,20,VERSION,
  77.         0xd000,22,REVISION,
  78.         0x80,24,(ULONG) &ExLibID[0],
  79.         (ULONG) 0
  80. };
  81. #else
  82. {
  83.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  84.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  85.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  86.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  87.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  88.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  89.  (ULONG) 0
  90. };
  91. #endif
  92.  
  93. /* ----------------------------------------------------------------------------------------
  94.    ! L_OpenLibs:
  95.    !
  96.    ! Since this one is called by InitLib, libraries not shareable between Processes or
  97.    ! libraries messing with RamLib (deadlock and crash) may not be opened here.
  98.    !
  99.    ! You may bypass this by calling this function fromout LibOpen, but then you will
  100.    ! have to a) protect it by a semaphore and b) make sure, that libraries are only
  101.    ! opened once (when using globa library bases).
  102.    ---------------------------------------------------------------------------------------- */
  103.  
  104. ULONG __saveds __stdargs L_OpenLibs(void)
  105. {
  106.  SysBase = (*((struct ExecBase **) 4));
  107.  
  108.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  109.  if(!IntuitionBase) return(FALSE);
  110.  
  111.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  112.  if(!GfxBase) return(FALSE);
  113.  
  114.  GadToolsBase = (struct GadToolsBase *) OpenLibrary("gadtools.library", 36);
  115.  if(!GadToolsBase) return(FALSE);
  116.  
  117.  DOSBase = (struct DOSBase *) OpenLibrary("dos.library", 0L);
  118.  if(!DOSBase) return(FALSE);
  119.  
  120.  ExampleBase->exb_SysBase       = SysBase;
  121.  ExampleBase->exb_IntuitionBase = IntuitionBase;
  122.  ExampleBase->exb_GfxBase       = GfxBase;
  123.  ExampleBase->exb_GadToolsBase  = GadToolsBase;
  124.  ExampleBase->exb_DOSBase       = DOSBase;
  125.  
  126.  return(TRUE);
  127. }
  128.  
  129. /* ----------------------------------------------------------------------------------------
  130.    ! L_CloseLibs:
  131.    !
  132.    ! This one by default is called by ExpungeLib, which only can take place once
  133.    ! and thus per definition is single-threaded.
  134.    !
  135.    ! When calling this fromout LibClose instead, you will have to protect it by a
  136.    ! semaphore, since you don't know whether a given CloseLibrary(foobase) may cause a Wait().
  137.    ! Additionally, there should be protection, that a library won't be closed twice.
  138.    ---------------------------------------------------------------------------------------- */
  139.  
  140. void __saveds __stdargs L_CloseLibs(void)
  141. {
  142.         if (GfxBase)
  143.         {
  144.                 CloseLibrary((struct Library *) GfxBase);
  145.         }
  146.  
  147.         if (IntuitionBase)
  148.         {
  149.                 CloseLibrary((struct Library *) IntuitionBase);
  150.         }
  151.  
  152.         if (GadToolsBase)
  153.         {
  154.                 CloseLibrary((struct Library *) GadToolsBase);
  155.         }
  156.  
  157.         if (DOSBase)
  158.         {
  159.                 CloseLibrary((struct Library *) DOSBase);
  160.         }
  161. }
  162.